package sg.edu.nus.iss.vmcs.maintenance;

/*
 * Copyright 2011 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */

import java.awt.event.*;
import java.awt.*;

import sg.edu.nus.iss.vmcs.ui.EventArgs;
import sg.edu.nus.iss.vmcs.ui.VMCSEventHandler;

/**
 * This class represents the control object that monitors the events in the 
 * Price Display and performs actions in response to data being entered into the
 * text field. It implements ActionListener interface from Java AWT Event Package.
 *
 * @version 1.0  08/12/2011
 * @author Team 7S - SE19
 */

public class PriceDisplayListener implements ActionListener, VMCSEventHandler {
	private MaintenanceController mctrl;

/**
 * This constructor creates an instance of the Price Display Listener.
 * It receives the reference for the Maintenance Controller object.
 * @param mc Maintenance Controller
 * @see MaintenanceController
 */	
	public PriceDisplayListener(MaintenanceController mc) {
		mctrl = mc;
	}

/**
 * Invoked when an action occurs on the price display (text field). 
 * Implemented as a part of interface.
 * @param e ActionEvent 
 * @see MaintenanceController#setPrice(int) 
 */	
	public void actionPerformed(ActionEvent e) {
		TextField txt;

		String sp;
		int ip;

		txt = (TextField) e.getSource();
		sp = txt.getText();

		ip = Integer.parseInt(sp);

		mctrl.setPrice(ip);
	}
	
	public void vmcsActionPerformed(Object eventSource, EventArgs args) {
		ActionEvent event = new ActionEvent(null, 0, null);
		this.actionPerformed(event);
	}

}